﻿using System;
using System.Collections.Generic;
using Wolfbyte.Core.Mvc.Routing;

namespace Wolfbyte.Core.Mvc.Facilities
{
    public class MvcSupportConfiguration
    {
        protected bool includeDefaultRoute = true;
        protected IList<IRouteRegistrar> routeRegistrars;
        protected IList<Type> controllerTypes;

        public bool IncludeDefaultRoute
        {
            get { return includeDefaultRoute; }
            set { includeDefaultRoute = value; }
        }

        public IEnumerable<IRouteRegistrar> RouteRegistrars
        {
            get
            {
                foreach (var routeRegistrar in routeRegistrars)
                    yield return routeRegistrar;
                if (includeDefaultRoute)
                    yield return new DefaultRouteRegistrar();
            }
        }

        public IEnumerable<Type> ControllerTypes
        {
            get
            {
                 return controllerTypes;
            }
        }

        public void AddRoute( IRouteRegistrar routeRegistrar)
        {
            if( routeRegistrar == null)
                throw new ArgumentException("Route Registrar cannot be null", "routeRegistrar");
            routeRegistrars.Add(routeRegistrar);
        }

        public void AddControllerType( Type controllerType )
        {
            if( controllerType == null )
                throw new ArgumentException("Controller Type cannot be null", "controllerType");
            controllerTypes.Add(controllerType);
        }

        public MvcSupportConfiguration()
        {
            includeDefaultRoute = true;
            routeRegistrars = new List<IRouteRegistrar>();
            controllerTypes = new List<Type>();
        }
    }
}
